﻿Imports BookOrderingSystem.BOSDataSetTableAdapters

Public Class Login
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        RegisterHyperLink.NavigateUrl = "Register.aspx?ReturnUrl=" + HttpUtility.UrlEncode(Request.QueryString("ReturnUrl"))
        ForgetPasswordHyperLink.NavigateUrl = "ForgetPassword.aspx?ReturnUrl=" + HttpUtility.UrlEncode(Request.QueryString("ReturnUrl"))

    End Sub

    Protected Sub LoginButton_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim loginSuccess As Boolean = False
        Dim userEnterName As String = LoginUser.UserName
        Dim userEnterPassword As String = LoginUser.Password
        Dim userid As String = ""

        Dim adap As New UsersTableAdapter
        Dim userTable = adap.GetData()
        For Each item As BookOrderingSystem.BOSDataSet.UsersRow In userTable
            Dim userName As String = item.UserName
            Dim userPassword As String = item.UserPassword

            If String.Equals(userEnterName, userName) Then
                If String.Equals(userEnterPassword, userPassword) Then
                    loginSuccess = True
                    userid = item.UserId
                    Exit For
                End If
            Else
                loginSuccess = False
            End If
        Next

        If (loginSuccess = True) Then
            Session("IsUserLogin") = True
            Session("UserName") = LoginUser.UserName
            Session("UserId") = CInt(userid)
        End If
        'Response.Redirect("~/Admin/index.aspx")
    End Sub
End Class